package com.a16.yuejian.yuejian.model;

import com.a16.yuejian.yuejian.javabean.Club;
import com.a16.yuejian.yuejian.javabean.Collected;
import com.a16.yuejian.yuejian.javabean.Exist;
import com.a16.yuejian.yuejian.javabean.Master;
import com.a16.yuejian.yuejian.javabean.Success;
import com.a16.yuejian.yuejian.javabean.Video;
import com.a16.yuejian.yuejian.listener.ClubListListener;
import com.a16.yuejian.yuejian.listener.ClubListener;
import com.a16.yuejian.yuejian.listener.CollectedListener;
import com.a16.yuejian.yuejian.listener.ExistListener;
import com.a16.yuejian.yuejian.listener.Listener;
import com.a16.yuejian.yuejian.listener.MasterListener;
import com.a16.yuejian.yuejian.listener.SuccessListener;
import com.a16.yuejian.yuejian.service.ClubService;
import com.a16.yuejian.yuejian.service.UserService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by 王子恒 on 2017/9/28.
 */

public class ClubModel {
    private Retrofit retrofit;
    public ClubModel(){
        retrofit =new Retrofit.Builder()
                .baseUrl("http://10.0.2.2:8080/neu_yuejian201/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void allclub(final ClubListListener listener){
        ClubService clubService=retrofit.create(ClubService.class);
        Call<List<Club>> call=clubService.allclub();
        call.enqueue(new Callback<List<Club>>() {
            @Override
            public void onResponse(Call<List<Club>> call, Response<List<Club>> response) {
                if (response.isSuccessful() && response.body()!=null)
                {
                    listener.onResponse(response.body());
                }
            }

            @Override
            public void onFailure(Call<List<Club>> call, Throwable t) {

            }
        });
    }
    public void getclub(String clubid, final ClubListener listener){
            ClubService clubService=retrofit.create(ClubService.class);
        Call<Club> call=clubService.getclub(clubid);
        call.enqueue(new Callback<Club>() {
            @Override
            public void onResponse(Call<Club> call, Response<Club> response) {
                listener.onResponse(response.body());
            }

            @Override
            public void onFailure(Call<Club> call, Throwable t) {

            }
        });
    }

    public void getclubcoach(String clubid, final Listener listener){
        ClubService clubService=retrofit.create(ClubService.class);
        Call<List<Master>> call=clubService.getclubcoach(clubid);
        call.enqueue(new Callback<List<Master>>() {
            @Override
            public void onResponse(Call<List<Master>> call, Response<List<Master>> response) {
                listener.onResponse(response.body());

            }

            @Override
            public void onFailure(Call<List<Master>> call, Throwable t) {

            }
        });

    }

    public void getclubvideo(final Listener listener){
        ClubService clubService = retrofit.create(ClubService.class);
        Call<List<Video>> call = clubService.getclubvideo();
        call.enqueue(new Callback<List<Video>>() {
            @Override
            public void onResponse(Call<List<Video>> call, Response<List<Video>> response) {
                listener.onResponse(response.body());
            }

            @Override
            public void onFailure(Call<List<Video>> call, Throwable t) {

            }
        });
    }

    public void follow(String club_id, String uid, String type, final SuccessListener listener){
        ClubService clubService = retrofit.create(ClubService.class);
        Call call = clubService.follow(club_id,uid,type);
        Callback<Success> callback = new Callback<Success>() {
            @Override
            public void onResponse(Call<Success> call, Response<Success> response) {
                listener.onResponse(response.body());
            }

            @Override
            public void onFailure(Call<Success> call, Throwable t) {

            }
        };
        call.enqueue(callback);
    }

    public void isCollected(String club_id, String uid, String type, final CollectedListener listener){
        ClubService clubService = retrofit.create(ClubService.class);
        Call call = clubService.isCollected(club_id,uid,type);
        Callback<Collected> callback = new Callback<Collected>() {
            @Override
            public void onResponse(Call<Collected> call, Response<Collected> response) {
                listener.onResponse(response.body());
            }

            @Override
            public void onFailure(Call<Collected> call, Throwable t) {

            }
        };
        call.enqueue(callback);
    }

}
